04. 解决方案:条件语句
练习解决方案:哪个奖品
以下是这道练习中我的解决方案!
points = 174
if points <=0:
result = " Invalid score."
elif points <= 50:
result = "Congratulations! You won a wooden rabbit!"
elif points <= 150:
result = "Oh dear, no prize this time."
elif points <= 180:
result = "Congratulations! You won a wafer-thin mint!"
elif points <= 200:
result = "Congratulations! You won a penguin!"
else:
result = " Invalid score."
print(result)
输出:
Congratulations! You won a wafer-thin mint!
最后一种情况用
else
条件语句捕获,因为在检查了其他条件后,没有其他可能的奖品值了。